package com.atguigu.admin.service.impl;

import com.atguigu.admin.mapper.AdminUserMapper;
import com.atguigu.admin.param.AdminUserParam;
import com.atguigu.admin.pojo.AdminUser;
import com.atguigu.admin.service.AdminUserService;
import com.atguigu.constants.UserConstants;
import com.atguigu.utils.MD5Util;
import com.atguigu.utils.R;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.management.Query;

@Service
public class AdminUserServiceImpl extends ServiceImpl<AdminUserMapper, AdminUser> implements AdminUserService {

    @Autowired
    private AdminUserMapper adminUserMapper;

    @Override
    public R login(AdminUserParam adminUserParam) {

        String newPwd = MD5Util.encode(adminUserParam.getUserPassword() + UserConstants.USER_SALT);
        QueryWrapper<AdminUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_account",adminUserParam.getUserAccount());
        queryWrapper.eq("user_password",newPwd);
        AdminUser adminUser = this.getOne(queryWrapper);
        if(adminUser==null){
            return R.fail("账号或者密码错误");
        }
        return R.ok("登录成功",adminUser);
    }
}
